home *** CD-ROM | disk | FTP | other *** search
- // GETINFO SCRIPTING
- // IMDB (US) import with small picture
- // Filmpub (CZ) import, made by Marek Pospisil
-
- (***************************************************
- * Movie importation script for: *
- * IMDB (US), http://us.imdb.com *
- * FilmPub (CZ), http://filmpub.atlas.cz *
- * *
- * (c) 2002-2004 Antoine Potten *
- * software@antp.be *
- * Contributors : *
- * Danny Falkov *
- * Kai Blankenhorn *
- * *
- * For use with Ant Movie Catalog 3.4.0 *
- * www.antp.be/software/moviecatalog *
- * *
- * This program is free software; you can *
- * redistribute it and/or modify it under the *
- * terms of the GNU General Public License as *
- * published by the Free Software Foundation; *
- * either version 2 of the License, or (at your *
- * option) any later version. *
- ***************************************************)
-
- program IMDbFilmPub;
-
- const
- DescriptionToImport = 2;
- {
- 2 = import longest
- 1 = import short (from main page, faster)
- 0 = display list to select a description
- }
-
-
- BASEURL = 'http://filmpub.atlas.cz';
- // true ... bude vyplneno, false .. nebude vyplneno
- cOriginalTitle = false;
- cTranslatedTitle = true;
- cDescription = true;
- cComments = true;
-
- var
- MovieName: string;
- MovieURL: string;
-
- function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
- var
- i: Integer;
- begin
- result := -1;
- if StartAt < 0 then
- StartAt := 0;
- for i := StartAt to List.Count-1 do
- if Pos(Pattern, List.GetString(i)) <> 0 then
- begin
- result := i;
- Break;
- end;
- end;
-
- procedure AnalyzePage(Address: string);
- var
- Page: TStringList;
- begin
- Page := TStringList.Create;
- Page.Text := GetPage(Address);
- if pos('<title>IMDb', Page.Text) = 0 then
- begin
- AnalyzeMoviePage(Page)
- end else
- begin
- PickTreeClear;
- AddMoviesTitles(Page, '<b>Exact Matches</b>');
- AddMoviesTitles(Page, '<b>Partial Matches</b>');
- AddMoviesTitles(Page, '<b>Approximate Matches</b>');
- if PickTreeExec(Address) then
- AnalyzePage(Address);
- end;
- Page.Free;
- end;
-
- procedure AnalyzeMoviePage(Page: TStringList);
- var
- Line, Value, Value2, FullValue: string;
- LineNr: Integer;
- BeginPos, EndPos, DescrImport: Integer;
- begin
- DescrImport := DescriptionToImport;
- if (DescrImport <> 1) and (Pos('<a href="plotsummary">', Page.Text) = 0) then
- DescrImport := 1;
-
- MovieURL := 'http://imdb.com/title/tt' + Copy(Page.Text, Pos('?pending&add=', Page.Text) + 17, 7);
-
- // URL
- SetField(fieldURL, MovieURL);
-
- // Original Title & Year
- LineNr := FindLine('<title>', Page, 0);
- Line := Page.GetString(LineNr);
- if LineNr > -1 then
- begin
- BeginPos := pos('<title>', Line);
- if BeginPos > 0 then
- BeginPos := BeginPos + 7;
- EndPos := pos('(', Line);
- if EndPos = 0 then
- EndPos := Length(Line);
- Value := copy(Line, BeginPos, EndPos - BeginPos - 1);
- HTMLDecode(Value);
- SetField(fieldOriginalTitle, Value);
- BeginPos := pos('(', Line) + 1;
- if BeginPos > 0 then
- begin
- EndPos := Pos('/I', Line);
- if EndPos < BeginPos then
- EndPos := Pos(')', Line);
- Value := copy(Line, BeginPos, EndPos - BeginPos);
- SetField(fieldYear, Value);
- end;
- end;
-
- // Rating
- LineNr := FindLine('User Rating:', Page, 0);
- if LineNr > -1 then
- begin
- Line := Page.GetString(LineNr + 4);
- if Pos('/10', Line) > 0 then
- begin
- BeginPos := pos('<b>', Line) + 3;
- Value := IntToStr(Round(StrToInt(StrGet(Line, BeginPos), 0) + (StrToInt(StrGet(Line, BeginPos + 2), 0) / 10)));
- SetField(fieldRating, Value);
- end;
- end;
-
- // Picture
- LineNr := FindLine('<img border="0" alt="cover"', Page, 0);
- if LineNr > -1 then
- begin
- Line := Page.GetString(LineNr);
- BeginPos := pos('src="', Line) + 4;
- Delete(Line, 1, BeginPos);
- EndPos := pos('"', Line);
- Value := copy(Line, 1, EndPos - 1);
- GetPicture(Value, False); // False = do not store picture externally ; store it in the catalog file
- end;
-
- // Director
- LineNr := FindLine('Directed by', Page, 0);
- if LineNr > -1 then
- begin
- FullValue := '';
- Line := Page.GetString(LineNr + 1);
- repeat
- BeginPos := pos('">', Line) + 2;
- EndPos := pos('</a>', Line);
- Value := copy(Line, BeginPos, EndPos - BeginPos);
- if (Value <> '(more)') and (Value <> '') then
- begin
- if FullValue <> '' then
- FullValue := FullValue + ', ';
- FullValue := FullValue + Value;
- end;
- Delete(Line, 1, EndPos);
- until Pos('</a>', Line) = 0;
- HTMLDecode(FullValue);
- SetField(fieldDirector, FullValue);
- end;
-
- // Actors
- LineNr := FindLine('ast overview', Page, 0);
- if LineNr = -1 then
- LineNr := FindLine('redited cast', Page, 0);
- if LineNr > -1 then
- begin
- FullValue := '';
- Line := Page.GetString(LineNr);
- repeat
- BeginPos := Pos('<td valign="top">', Line);
- if BeginPos > 0 then
- begin
- Delete(Line, 1, BeginPos);
- Line := copy(Line, 25, Length(Line));
- BeginPos := pos('">', Line) + 2;
- EndPos := pos('</a>', Line);
- if EndPos = 0 then
- EndPos := Pos('</td>', Line);
- Value := copy(Line, BeginPos, EndPos - BeginPos);
- if (Value <> '(more)') and (Value <> '') then
- begin
- BeginPos := pos('.... </td><td valign="top">', Line);
- if BeginPos > 0 then
- begin
- EndPos := pos('</td></tr>', Line);
- BeginPos := BeginPos + 27;
- Value2 := copy(Line, BeginPos, EndPos - BeginPos);
- if Value2 <> '' then
- begin
- Value := Value + ' (as ' + Value2 + ')';
- end;
- end;
- if FullValue <> '' then
- FullValue := FullValue + ', ';
- FullValue := FullValue + Value;
- end;
- EndPos := Pos('</td></tr>', Line);
- Delete(Line, 1, EndPos);
- end else
- begin
- Line := '';
- end;
- until Line = '';
- HTMLDecode(FullValue);
- SetField(fieldActors, FullValue);
- end;
-
- //Country
- LineNr := FindLine('Country:', Page, 0);
- if LineNr > -1 then
- begin
- Line := Page.GetString(LineNr + 1);
- BeginPos := pos('/">', Line) + 3;
- EndPos := pos('</a>', Line);
- Value := copy(Line, BeginPos, EndPos - BeginPos);
- HTMLDecode(Value);
- SetField(fieldCountry, Value);
- end;
-
- //Category
- LineNr := FindLine('Genre:', Page, 0);
- if LineNr > -1 then
- begin
- Line := Page.GetString(LineNr + 1);
- BeginPos := pos('/">', Line) + 3;
- EndPos := pos('</a>', Line);
- Value := copy(Line, BeginPos, EndPos - BeginPos);
- HTMLDecode(Value);
- SetField(fieldCategory, Value);
- end;
-
- //Description
- LineNr := FindLine('Plot Summary:', Page, 0);
- if LineNr < 1 then
- LineNr := FindLine('Plot Outline:', Page, 0);
- if LineNr > -1 then
- begin
- Line := Page.GetString(LineNr);
- BeginPos := pos('</b>', Line) + 5;
- EndPos := pos('<a href="/rg/', Line);
- if EndPos < 1 then
- begin
- Line := Line + Page.GetString(LineNr+1);
- EndPos := pos('<a href="/rg/', Line);
- if EndPos < 1 then
- EndPos := pos('<br><br>', Line);
- if EndPos < 1 then
- EndPos := Length(Line);
- end;
- Value := copy(Line, BeginPos, EndPos - BeginPos);
- HTMLDecode(Value);
- HTMLRemoveTags(Value);
- case DescrImport of
- 0:
- begin
- PickListClear;
- PickListAdd(Value);
- GetDescriptions(GetField(fieldURL) + 'plotsummary');
- if PickListExec('Select a description for "' + MovieName + '"', Value) then
- SetField(fieldDescription, Value);
- end;
- 1:
- SetField(fieldDescription, Value);
- 2:
- SetField(fieldDescription, GetDescriptions(MovieURL + 'plotsummary'));
- end;
- end;
-
- // Comments
- LineNr := FindLine('<b>Summary:</b>', Page, 0);
- if LineNr > -1 then
- begin
- Value := '';
- repeat
- LineNr := LineNr + 1;
- Line := Page.GetString(LineNr);
- EndPos := Pos('</blockquote>', Line);
- if EndPos = 0 then
- EndPos := Length(Line)
- else
- EndPos := EndPos - 1;
- Value := Value + Copy(Line, 1, EndPos) + ' ';
- until Pos('</blockquote>', Line) > 0;
- HTMLDecode(Value);
- Value := StringReplace(Value, '<br>', #13#10);
- Value := StringReplace(Value, #13#10+' ', #13#10);
- SetField(fieldComments, Value);
- end;
-
- // Length
- LineNr := FindLine('Runtime:', Page, 0);
- if LineNr > -1 then
- begin
- Line := Page.GetString(LineNr + 1);
- EndPos := pos(' min', Line);
- if EndPos = 0 then
- EndPos := pos(' /', Line);
- if EndPos = 0 then
- EndPos := Length(Line);
- if Pos(':', Line) < EndPos then
- BeginPos := Pos(':', Line) + 1
- else
- BeginPos := 1;
- Value := copy(Line, BeginPos, EndPos - BeginPos);
- SetField(fieldLength, Value);
- end;
-
- // Language
- LineNr := FindLine('Language:', Page, 0);
- if LineNr > -1 then
- begin
- Line := Page.GetString(LineNr + 1);
- BeginPos := pos('/">', Line) + 3;
- EndPos := pos('</a>', Line);
- if EndPos = 0 then
- EndPos := Length(Line);
- Value := copy(Line, BeginPos, EndPos - BeginPos);
- SetField(fieldLanguages, Value);
- end;
-
- // DisplayResults;
- end;
-
- function GetDescriptions(Address: string): string;
- var
- Line, Value: string;
- LineNr: Integer;
- BeginPos, EndPos,Longest: Integer;
- Page: TStringList;
- begin
- Result := '';
- Longest := 0;
- Page := TStringList.Create;
- Page.Text := GetPage(Address);
- LineNr := FindLine('<p class="plotpar">', Page, 0);
- while LineNr > -1 do
- begin
- Value := '';
- repeat
- Line := Page.GetString(LineNr);
- BeginPos := pos('"plotpar">', Line);
- if BeginPos > 0 then
- BeginPos := BeginPos + 10
- else
- BeginPos := 1;
- EndPos := pos('</p>', Line);
- if EndPos < 1 then
- EndPos := Length(Line) + 1;
- if Value <> '' then
- Value := Value + ' ';
- Value := Value + copy(Line, BeginPos, EndPos - BeginPos);
- LineNr := LineNr + 1;
- until (pos('</p>', Line) > 0) or (LineNr = Page.Count);
- HTMLDecode(Value);
- HTMLRemoveTags(Value);
- PickListAdd(Value);
-
- if Length(Value) > Longest then
- begin
- Result := Value;
- Longest := Length(Value);
- end;
-
- LineNr := FindLine('<p class="plotpar">', Page, LineNr);
- end;
- Page.Free;
- end;
-
- procedure AddMoviesTitles(Page: TStringList; Tag: string);
- var
- Line: string;
- LineNr: Integer;
- MovieTitle, MovieAddress: string;
- StartPos: Integer;
- begin
- LineNr := FindLine(tag, Page, 0);
- if LineNr > -1 then
- begin
- Line := Page.GetString(LineNr);
- HTMLRemoveTags(Line);
- PickTreeAdd(Trim(Line), '');
- LineNr := LineNr + 5;
- Line := Page.GetString(LineNr);
- repeat
- StartPos := pos('href="', Line) + 5;
- Delete(Line, 1, StartPos);
- MovieAddress := Copy(Line, 1, pos('">', Line) - 1);
- StartPos := Pos('">', Line) + 2;
- MovieTitle := Copy(Line, StartPos, Pos('</td>', Line) - StartPos);
- HTMLRemoveTags(MovieTitle);
- HTMLDecode(Movietitle);
- PickTreeAdd(MovieTitle, 'http://us.imdb.com' + MovieAddress);
- LineNr := LineNr + 2;
- Line := Page.GetString(LineNr);
- until Pos('</table>', Line) > 0;
- end;
- end;
-
-
- (* ****************************************************************************
- *
- * FilmPub section
- *
- * ****************************************************************************)
-
- function iPos (Substr: String; S: String): Integer;
- begin
- Substr := AnsiLowerCase(Substr);
- S := AnsiLowerCase(S);
- Result := Pos(Substr, S);
- end;
-
- function FormatText(T: String): String;
- var BeginPos: Integer;
- begin
- BeginPos := iPos(' ', T);
- while (BeginPos > 0 ) do
- begin
- Delete(T, BeginPos, 1);
- BeginPos := iPos(' ', T);
- end;
-
- T := StringReplace(T, #13#10, '');
- T := StringReplace(T, '</p>', #13#10#13#10);
- T := StringReplace(T, '</P>', #13#10#13#10);
- T := StringReplace(T, '<br>', #13#10);
- T := StringReplace(T, '<BR>', #13#10);
- Result := T;
- end;
-
- procedure AnalyzePageFilmPub(Address: string);
- var
- Line, iLine, aLine, MovieTitle, MovieAddress: string;
- BeginPos, EndPos: Integer;
- begin
- Line := GetPage(Address);
-
- PickTreeClear;
- PickTreeAdd('NalezenĪ filmy:', '');
-
- BeginPos := iPos('<a href="film.aspx', Line);
- while (BeginPos > 0 ) do
- begin
- Line := Copy(Line, BeginPos, Length(Line));
- EndPos := iPos('</a>', Line);
- iLine := Copy(Line, 0, EndPos-1);
- Line := Copy(Line, EndPos, Length(Line));
-
- BeginPos := iPos('"', iLine);
- aLine := Copy(iLine, BeginPos+1, Length(iLine));
- EndPos := iPos('"', aLine);
- aLine := Copy(iLine, BeginPos+1, EndPos-1);
- MovieAddress := BASEURL + '/' + aLine;
- BeginPos := iPos('>', iLine);
- MovieTitle := Trim(Copy(iLine, BeginPos+1, Length(iLine)));
- PickTreeAdd(MovieTitle, MovieAddress);
-
- BeginPos := iPos('<a href="film.aspx', Line);
- end;
- if PickTreeExec(Address) then
- AnalyzeMoviePageFilmPub(Address);
- end;
-
-
- procedure AnalyzeMoviePageFilmPub(Address: string);
- var
- Line, iLine, Value, MovieAddress: string;
- BeginPos, EndPos: Integer;
- begin
- Line := GetPage(Address);
-
- BeginPos := iPos('Detail filmu', Line);
- Line := Copy(Line, BeginPos, Length(Line));
-
- BeginPos := iPos('<h1>', Line);
- EndPos := iPos('</h1>', Line);
- iLine := Copy(Line, BeginPos, EndPos-BeginPos);
- EndPos := iPos('<span>', iLine);
- Value := Copy(iLine, 0, EndPos-1);
- HTMLRemoveTags(Value);
- HTMLDecode(Value);
- if cTranslatedTitle then
- SetField(fieldTranslatedTitle, Value);
-
- Value := Copy(iLine, EndPos, Length(iLine));
- HTMLRemoveTags(Value);
- HTMLDecode(Value);
- if cOriginalTitle then
- SetField(fieldOriginalTitle, Value);
-
- BeginPos := iPos('clanek.aspx?articleId=', Line);
- Line := Copy(Line, BeginPos, Length(Line));
- EndPos := iPos('"', Line);
- MovieAddress := Copy(Line, 0, EndPos-1);
-
-
- Line := GetPage(BASEURL + '/' + MovieAddress);
- BeginPos := iPos('<p class="prolog"', Line);
- Line := Copy(Line, BeginPos, Length(Line));
- EndPos := iPos('</p>', Line);
- Value := Copy(Line, 0, EndPos-1);
- Value := FormatText(Value);
- HTMLRemoveTags(Value);
- HTMLDecode(Value);
- if cDescription then
- SetField(fieldDescription, Value);
-
- Line := Copy(Line, EndPos+Length('</p>'), Length(Line));
- EndPos := iPos('</div>', Line);
- Value := Copy(Line, 0, EndPos-1);
-
- Value := FormatText(Value);
- HTMLRemoveTags(Value);
- HTMLDecode(Value);
- if cComments then
- SetField(fieldComments, Value);
- end;
-
- (* ****************************************************************************
- *
- * Main section
- *
- * ****************************************************************************)
-
- begin
- if CheckVersion(3,4,0) then
- begin
- MovieName := GetField(fieldOriginalTitle);
- if MovieName = '' then
- MovieName := GetField(fieldTranslatedTitle);
- if Input('IMDb Import', 'Enter the title of the movie:', MovieName) then
- begin
- AnalyzePage('http://us.imdb.com/Tsearch?title='+UrlEncode(MovieName));
- AnalyzePageFilmPub(BASEURL+'/hledej.aspx?findString='+UrlEncode(MovieName));
- DisplayResults;
- end;
- end
- else
- ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.0)');
- end.
-